package cn.itcast.bos.web.action.system;

import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.service.system.PermissionService;
import cn.itcast.bos.web.action.common.BaseAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller
@Namespace("/")
@ParentPackage("struts-default")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PermissionAction extends BaseAction<Permission> {
    @Autowired
    private PermissionService permissionService;

    @Action(value = "permission_list")
    public void findAll() {
        List<Permission> permissions = permissionService.findAll();
        writeJson(permissions);
    }

    @Action(value = "permission_save", results = {@Result(name = "success", location = "./pages/system/permission.html", type = "redirect")})
    public String save() {
        permissionService.save(model);
        return SUCCESS;
    }
}
